﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DLL
{
    public class BillDetailRepo
    {
        public void Add(BillDetail billDetail)
        {
            using (RetailManagementEntities dbContext = new RetailManagementEntities())
            {
                dbContext.BillDetail.Add(billDetail);
                dbContext.SaveChanges();
            }
        }

        public void Update(BillDetail billDetail)
        {
            using (RetailManagementEntities dbContext = new RetailManagementEntities())
            {
                dbContext.Entry(billDetail).State = EntityState.Modified;
                dbContext.SaveChanges();
            }
        }

        public List<BillDetail> GetOfBill(int billId)
        {
            using (RetailManagementEntities dbContext = new RetailManagementEntities())
            {
                return dbContext.BillDetail.Where(x => x.BillId == billId).ToList();
            }
        }

        public List<pGetBIllDetailByBillId_Result> GetBillDetailByBillId(int billId)
        {
            using (RetailManagementEntities dbContext = new RetailManagementEntities())
            {
                return dbContext.pGetBIllDetailByBillId(billId).ToList();
            }
        }

        public void Delete(int billDetailId)
        {
            using (RetailManagementEntities dbContext = new RetailManagementEntities())
            {
                BillDetail billDetail = dbContext.BillDetail.Find(billDetailId);
                dbContext.BillDetail.Remove(billDetail);
                dbContext.SaveChanges();
            }
        }
    }
}
